package cn.fxl.system.controller;
import cn.fxl.basic.pageList.GmResult;
import cn.fxl.basic.result.AjaxResult;
import cn.fxl.system.domain.SystemDictionaryType;
import cn.fxl.system.query.SystemDictionaryTypeQuery;
import cn.fxl.system.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
public class SystemDictionaryTypeController {
    @Autowired
    public ISystemDictionaryTypeService iSystemDictionaryTypeService;
    /**
     * 获取所有
     * @return
     */
    @GetMapping
    public List<SystemDictionaryType> getAll(){
        return iSystemDictionaryTypeService.getAll();
    }

    /**
     * 获取单个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public SystemDictionaryType getOne(@PathVariable("id") Long id){
        return iSystemDictionaryTypeService.getOne(id);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            iSystemDictionaryTypeService.remove(id);
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"删除失败");
        }
    }

    /**
     * 新增和修改
     * @param systemDictionaryType
     * @return
     */
    @PutMapping
    public AjaxResult saveAndUpdate(@RequestBody SystemDictionaryType systemDictionaryType){
        try {
            if (systemDictionaryType.getId()==null){
                iSystemDictionaryTypeService.save(systemDictionaryType);
            }else {
                iSystemDictionaryTypeService.update(systemDictionaryType);
            }
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"操作失败");
        }
    }

    /**
     * 高级查询 和分页查询
     * @param systemDictionaryTypeQuery
     * @return
     */
    @PostMapping
    public GmResult<SystemDictionaryType > querPage(@RequestBody SystemDictionaryTypeQuery systemDictionaryTypeQuery){
        return iSystemDictionaryTypeService.Pagequery(systemDictionaryTypeQuery);
    }

    @PatchMapping
    public AjaxResult pathchdel(@RequestBody Long [] a){
        try {
            iSystemDictionaryTypeService.pathchdel(a);
            return new AjaxResult();
        } catch (Exception e) {
            return new AjaxResult(false,"删除失败");
        }
    }
}
